<?php

require_once dirname(__FILE__) . '/TestCase.php';

class Auth_Vidoop_Secure_ImageShieldAPITest extends Auth_Vidoop_Secure_TestCase {

	private $categories;

	public function __construct() {
		parent::__construct();

		$this->categories = array( 'cars0001', 'people01', 'lksnkys1', 'wldanml1', 
			'castles1', 'houses01', 'trains01', 'flowers1', 'dogs0001', 'food0001', 
			'skyscrp1', 'stndgls1', 'muscins1', 'tysngms1', 'cats0001', 'bevrags1', 
			'insects1', 'comptrs1', 'outspac1', 'birds001', 'boats001', 'airplns1', 
			'undrwtr1', 'money001', 'telphns1', 'clocks01',
		);
	}

	public function testAPICall() {
		$service = $this->get_service('imageshield');

		$args = array(
			'imageshield_length' => 3,
			'order_matters' => true,
			'width'  => 4,
			'height' => 3,
			'image_code_color' => 'Red',
			'bundle' => array_slice($this->categories, 0, 12),
			'user_id' => 'abc123',
		);

		$shield = $service->new_imageshield($args);

		$this->assertNotNull($shield->id);
		$this->assertEquals($args['imageshield_length'], $shield->imageshield_length);
		$this->assertEquals($args['order_matters'], $shield->order_matters);
		$this->assertEquals($args['width'], $shield->width);
		$this->assertEquals($args['height'], $shield->height);
		$this->assertEquals($args['image_code_color'], $shield->image_code_color);
		$this->assertEquals($this->config['base'] . '/vs/imageshields/' . $shield->id . '/image', $shield->image);
		$this->assertFalse($shield->attempted);
		$this->assertFalse($shield->authenticated);

		// attempt code verification
		$verify_result = $service->verify_code($shield->id, 'a');
		$this->assertFalse($verify_result);

		// see that verify attempt has been recorded
		$shield2 = $service->get_imageshield($shield->id);
		$this->assertEquals($shield->id, $shield2->id);
		$this->assertTrue($shield2->attempted);
		$this->assertFalse($shield2->authenticated);
	}

}
